//package com.etrans.web.gps.business.system.controller;
//
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.apache.commons.codec.binary.Base64;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import com.etrans.web.gps.base.controller.BaseController;
//import com.etrans.web.gps.business.system.domain.SysUser;
//import com.etrans.web.gps.business.system.domain.VehicleSharaVo;
//import com.etrans.web.gps.business.system.domain.VehicleVo;
//import com.etrans.web.gps.business.system.service.VehicleService;
//import com.etrans.web.gps.common.Constant;
//import com.etrans.web.gps.common.page.PageVo;
//import com.etrans.web.gps.util.grid.FlexiGridUtil;
///**
// * 
// * @author th
// * 
// * 处理车辆信息
// */
//@Controller
//@RequestMapping("/system/vehicle/*")
//public class VehicleController extends BaseController {
//	
//	private final static Logger logger = LoggerFactory.getLogger("VehicleBaseController");
//	
//	@Autowired
//	private VehicleService vehicleService;
//	
//	/**
//	 * 加载用户下的车辆信息
//	 * @param req
//	 * @param res
//	 * @param model
//	 * @return
//	 */
//	@RequestMapping(value="loadUserVehicle.html")
//	@ResponseBody
//	public  Map<String, Object> loadUserVehicle(HttpServletRequest req,HttpServletResponse res, Model model){
//		SysUser user = (SysUser)getSession().getAttribute(Constant.LOGIN_SESSION_NAME);
//		List<VehicleVo> vehicleList=vehicleService.queryVehicleByAuth(String.valueOf(user.getId()));
//		Map<String, Object> map=new HashMap<>();
//		map.put("vehicleList", vehicleList);
//		return map;
//	}
//	
//	/**
//	 * 根据关键字查询车辆
//	 * @param req
//	 * @param res
//	 * @param model
//	 * @return
//	 */
//	@RequestMapping(value="queryUserVehicle.html")
//	@ResponseBody
//	public  Map<String, Object> queryUserVehicle(HttpServletRequest req,HttpServletResponse res, Model model){
//		HashMap<String, Object> param=getReqParameters();
//		SysUser user = (SysUser)getSession().getAttribute(Constant.LOGIN_SESSION_NAME);
//		param.put("userId", user.getId());
//		
//		List<VehicleVo> vehicleList=vehicleService.queryVehicleByCondition(param);
//		Map<String, Object> map=new HashMap<>();
//		map.put("vehicleList", vehicleList);
//		return map;
//	}
//	/**
//	 * 根据传入用户权限，企业进行查询
//	 * 
//	 * @param whereMap HashMap<String,Object>
//	 * @return 车辆集合  List<VehicleVo>
//	 */
//	@RequestMapping(value="queryVehicleByAuthAndUnit.html")
//	@ResponseBody
//	public  Map<String, Object> queryVehicleByAuthAndUnit(HttpServletRequest req,HttpServletResponse res, Model model){
//		HashMap<String, Object> param=getReqParameters();
//		SysUser user = (SysUser)getSession().getAttribute(Constant.LOGIN_SESSION_NAME);
//		param.put("userId", user.getId());
//		
//		List<VehicleVo> vehicleList=vehicleService.queryVehicleByAuthAndUnit(param);
//		Map<String, Object> map=new HashMap<>();
//		map.put("vehicleList", vehicleList);
//		return map;
//	}
//	
//	/**
//	 * 进入车辆管理页面
//	 * @param req
//	 * @param res
//	 * @param model
//	 * @param dbKey
//	 * @return
//	 */
//	@RequestMapping(value="vehicle.html")
//	public  String getIntoVehicle(){
//		return "views/business/system/vehicle/vehicle";
//	}
//	
//	/**
//	 * 查询用户下的全部车辆
//	 */
//	@RequestMapping(value="loadVehicle.html")
//	@ResponseBody
//	public  PageVo loadVehicle(String paramsGrid){
//		Map<String, Object> param =  FlexiGridUtil.parseJSONParam(paramsGrid).getWhereParam();
//		SysUser user = (SysUser)getSession().getAttribute(Constant.LOGIN_SESSION_NAME);
//		param.put("userId", user.getId());
//        PageVo pageVo = new PageVo();
//        pageVo.setPage(Integer.parseInt(param.get("page").toString()));
//        pageVo.setTotal(vehicleService.queryVehicleByPageCount(param));
//        pageVo.setRows(vehicleService.queryVehicleByConditionByPage(param));
//        return  pageVo;
//	}
//	
//	/**
//	 * 分享车辆
//	 */
//	@RequestMapping(value="shareVehicle.html")
//	public String shareVehicle(String vehicleId,Model model){
//		HashMap<String, Object> param=getReqParameters();
//		VehicleVo vo =vehicleService.queryVehicleShare(param);
//		String url="views/business/system/vehicle/vehicleShareOverdue";
//		try{
//			Date nowDate=new Date();		
//			if(vo!=null){
//				String shareKey=vo.getShareKey();				
//				if(shareKey==null||"".equals(shareKey)){
//					return url;
//				}
//				String shareUrl=vo.getShareUrl();
//				if(shareUrl==null||"".equals(shareUrl)){
//					return url;
//				}
//				shareUrl=shareUrl.substring(shareUrl.indexOf("?"));
//				shareUrl=shareUrl.substring(shareUrl.indexOf("=")+1, shareUrl.indexOf("&"));
//				if(!shareUrl.equals(param.get("shareKey").toString())){
//					return url;
//				}
//				long databaseKey = Long.valueOf(new String(Base64.decodeBase64(shareKey)));
//				if(nowDate.getTime()<=databaseKey){
//					url="views/business/system/vehicle/vehicleShareMonitor";
//				}		
//				model.addAttribute("vehicleID",vo.getVehicleId());
//				model.addAttribute("CommNO",vo.getCommNo());
//				model.addAttribute("shareKey",vo.getShareKey());
//				model.addAttribute("RegistrationNO",vo.getRegistrationNO());
//			}				
//		}catch (Exception e) {
//			e.printStackTrace();
//			logger.info("分享车辆错误：{}",e);
//		}		
//		return url;		
//	}	
//	/**
//	 * 保存车辆分享期限
//	 */
//	@RequestMapping(value="saveVehicleShareDate.html")
//	@ResponseBody
//	public VehicleSharaVo saveVehicleShareDate(Long vehicleId,Model model){
//		VehicleSharaVo vehicleShara=new VehicleSharaVo();
//		Map<String, Object> param=getReqParameters();
//		try {
//			String shareKey=(String)param.get("shareKey");
//			String vid =(String)param.get("vehicleId");
//			String action =(String)param.get("action");
//			String path =(String)param.get("path");
//			param.put("shareUrl",path+"system/vehicle/shareVehicle.html?shareKey="+shareKey+"&vehicleId="+vid);
//			VehicleVo vo =vehicleService.queryVehicleShare(param);
//			if(vo!=null){
//				if(vo.getShareKey()!=null){
//					if("share".equals(action)){
//						vehicleService.saveVehicleShareDate(param);  //第一次分享
//						vehicleShara.setAction(action);
//						vehicleShara.setMsg("成功");
//					}else if("update".equals(action)){
//						vehicleService.updateVehicleShareDate(param);
//						vehicleShara.setAction(action);
//						vehicleShara.setMsg("成功");
//					}else if("stop".equals(action)){
//						param.put("shareKey", null);
//						param.put("shareUrl", null);
//						vehicleService.saveVehicleShareDate(param);
//						vehicleShara.setAction(action);
//						vehicleShara.setMsg("成功");
//					}				
//				}else{
//					if("share".equals(action)){
//						vehicleService.saveVehicleShareDate(param);  //第一次分享
//						vehicleShara.setAction(action);
//						vehicleShara.setMsg("成功");
//					}else{
//						vehicleShara.setAction(action);
//						vehicleShara.setMsg("没有分享记录，不能操作");
//					}			
//				}
//			}									
//		} catch (Exception e) {
//			e.printStackTrace();
//			vehicleShara.setMsg("分享失败");
//			logger.info("保存车辆分享期限错误：{}",e);
//		}
//		return vehicleShara;
//	}
//	
//	/**
//	 * 查询分享
//	 */
//	@RequestMapping(value="queryVehicleShare.html")
//	@ResponseBody
//	public VehicleSharaVo queryVehicleShare(Model model){
//		VehicleSharaVo vehicleShara=new VehicleSharaVo();
//		Map<String, Object> param=getReqParameters();
//		String msg="成功";
//		try {
//			VehicleVo vo =vehicleService.queryVehicleShare(param);
//			if(vo!=null){
//				if(vo.getShareUrl()!=null){
//					vehicleShara.setVehicleIdStr(vo.getShareUrl());
//					vehicleShara.setFlag("0");
//					if(vo.getShareKey()!=null){
//						vehicleShara.setOvertime(new String(Base64.decodeBase64(vo.getShareKey())));
//					}else{
//						vehicleShara.setOvertime("车辆未分享，无过期时间");
//					}
//					
//				}else{
//					vehicleShara.setVehicleIdStr("车辆无分享记录");
//					vehicleShara.setFlag("1");
//				}			
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//			msg="分享失败！";
//			logger.info("保存车辆分享期限错误：{}",e);
//		}
//		vehicleShara.setMsg(msg);		
//		return vehicleShara;
//	}
//	
//	/**
//	 * 根据车辆ID查车
//	 */
//	@RequestMapping(value="queryVehicleById.html")
//	@ResponseBody
//	public  VehicleVo queryVehicleById(String vehicleId){
//		Map<String, Object> param = new HashMap<>();
//		param.put("vehicleId", vehicleId);
//		VehicleVo vo = vehicleService.queryVehicleById(param);
//        return  vo;
//	}
//	
//	
//	/**
//	 * 根据车辆ID查车
//	 */
//	@RequestMapping(value="updateVehicleInfo.html")
//	@ResponseBody
//	public  VehicleSharaVo updateVehicleInfo(String vehicleId,String internal,String driverName,String phone,String remark){
//		VehicleSharaVo vehicleShara=new VehicleSharaVo();
//		try {
//			Map<String, Object> param = new HashMap<>();
//			param.put("vehicleId", vehicleId);
//			param.put("internal", internal);
//			param.put("driverName", driverName);
//			param.put("phone", phone);
//			param.put("remark", remark);
//			vehicleService.updateVehicleInfo(param);
//			vehicleShara.setMsg("0");
//		} catch (Exception e) {
//			vehicleShara.setMsg("1");
//		}
//		return vehicleShara;      
//	}
//	
//	@RequestMapping(value = "exportVehicles.html")
//	public void exportVehicles(HttpServletResponse response,HttpServletRequest request, String paramsGrid,
//			Integer StartPage, Integer EndPage) {
//		Map<String, Object> param =  FlexiGridUtil.parseJSONParam(paramsGrid).getWhereParam();
//		SysUser user = (SysUser)getSession().getAttribute(Constant.LOGIN_SESSION_NAME);
//		String[] titleArray = new String[9];
//		titleArray[0] = "车牌号码";
//		titleArray[1] = "企业名称";
//		titleArray[2] = "自编号";
//		titleArray[3] = "通信号";
//		titleArray[4] = "Sim卡号";
//		titleArray[5] = "司机名称";
//		titleArray[6] = "司机联系电话";
//		titleArray[7] = "安装日期";
//		titleArray[8] = "备注";
//
//		String[] columnArray = new String[9];
//		columnArray[0] = "VNAME";
//		columnArray[1] = "WNAME";
//		columnArray[2] = "internal_number";
//		columnArray[3] = "CommNO";
//		columnArray[4] = "simNo";
//		columnArray[5] = "DNAME";
//		columnArray[6] = "phone";
//		columnArray[7] = "setupDateTime";
//		columnArray[8] = "remark";
//		param.put("userId", user.getId());
//		List rows = vehicleService.queryAllVehicles(param);
//	//	exportExl(request,response, "车辆信息", titleArray, columnArray, rows);
//	}
//	
//	
//}
